import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;

public class BingCustomSearch {
    public static void main(String[] args) {
        String subscriptionKey = "70a1a0905cf3407687ac7ca607c6e88e";
        String customConfigId = "09476d47-083f-40b4-9c2d-d083fde3f793";
        String searchTerm = "村民";
        String urlString = "https://api.bing.microsoft.com/v7.0/custom/search?q=" + searchTerm + "&customconfig=" + customConfigId;

        try {
            URL url = new URL(urlString);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("GET");
            connection.setRequestProperty("Ocp-Apim-Subscription-Key", subscriptionKey);

            int responseCode = connection.getResponseCode();
            if (responseCode == HttpURLConnection.HTTP_OK) {
                JsonParser parser = new JsonParser();
                JsonObject jsonObject = (JsonObject) parser.parse(new java.util.Scanner(connection.getInputStream(), "UTF-8").useDelimiter("\\A").next());
                System.out.println(jsonObject.toString());
            } else {
                System.out.println("HTTP request failed with response code: " + responseCode);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

